float4x4 g_matWorldViewProject;
float4 g_vCamLookAtDir;
float4 g_vOffsetXY_WH;
float4 g_vTextureMAXWH_unused_unused;
float4 g_vFontColor;
float4 g_vPosition[4];

Texture TextPic;
sampler MeshTextPic = sampler_state
{
	Texture = <TextPic>;
	MagFilter = LINEAR;
	MipFilter = LINEAR;
	MinFilter = LINEAR;
	AddressU = Wrap;
	AddressV = Wrap;
};

struct VS_INPUT
{
	float VertexID			: TEXCOORD0;
};

struct VS_OUTPUT
{
    float4 Position			: POSITION;
	float2 UV				: TEXCOORD0;
};

VS_OUTPUT RenderSceneVS( VS_INPUT Input)
{
	VS_OUTPUT Output = (VS_OUTPUT)0;
	float4 vTempPos = float4(g_vPosition[Input.VertexID].xyz, 1.f);
	float4 vDistortedPos = vTempPos - g_vCamLookAtDir * 0.15f;
	vTempPos = mul(vTempPos, g_matWorldViewProject);
	float fNewZ = dot(vDistortedPos, float4(g_matWorldViewProject[0][2], g_matWorldViewProject[1][2], g_matWorldViewProject[2][2], g_matWorldViewProject[3][2]));
	Output.Position = float4(vTempPos.xy, fNewZ, vTempPos.w);
	
	if (0 == Input.VertexID)
	{
		Output.UV = float2(0.f, 1.f);
	}
	else if (1 == Input.VertexID)
	{
		Output.UV = float2(0.f, 0.f);
	}
	else if (2 == Input.VertexID)
	{
		Output.UV = float2(1.f, 1.f);
	}
	else
	{
		Output.UV = float2(1.f, 0.f);
	}
	Output.UV.x *= g_vOffsetXY_WH.z;
	Output.UV.y *= g_vOffsetXY_WH.w;
	Output.UV += g_vOffsetXY_WH.xy;
	Output.UV.x = Output.UV.x / g_vTextureMAXWH_unused_unused.x;
	Output.UV.y = Output.UV.y / g_vTextureMAXWH_unused_unused.y;
	return Output;
}

float4 RenderScenePS( VS_OUTPUT Input) : COLOR0
{
	float4 color = float4(g_vFontColor.rgb, tex2D(MeshTextPic, Input.UV.xy).a);
	return color;
}

technique DefaultTech
{    
    pass P0
    {
		AlphaBlendEnable = true;
		BlendOp = Add;
		SrcBlend = srcColor;
		DestBlend = InvSrcAlpha;
        FillMode = Solid;
        VertexShader = compile vs_3_0 RenderSceneVS();
        PixelShader  = compile ps_3_0 RenderScenePS();
    }
}